package com.yxhl.zoume.core.tripsmgmt.ui.fragment.tripsdetail;


import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewCompat;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.afollestad.materialdialogs.MaterialDialog;
import com.yxhl.protobuf.BizOrder;
import com.yxhl.protobuf.BizOrderResponse;
import com.yxhl.protobuf.Contract;
import com.yxhl.protobuf.JudgeEntry;
import com.yxhl.protobuf.OrderBizType;
import com.yxhl.protobuf.OrderPayStatus;
import com.yxhl.protobuf.OrderRideStatus;
import com.yxhl.zoume.R;
import com.yxhl.zoume.UIConstants;
import com.yxhl.zoume.common.ui.custom.CheckBoxLayout;
import com.yxhl.zoume.common.ui.custom.ListViewWrap;
import com.yxhl.zoume.common.ui.fragment.BaseFragment;
import com.yxhl.zoume.core.car.fragment.common.CancelCarOrderFeedbackFragment;
import com.yxhl.zoume.core.car.model.PayResultEvent;
import com.yxhl.zoume.core.func.appraisal.model.AppraisalDriverInfo;
import com.yxhl.zoume.core.func.appraisal.model.CommentOnDriverEvent;
import com.yxhl.zoume.core.func.appraisal.ui.activity.AppraisalConfirmActivity;
import com.yxhl.zoume.core.func.pay.model.CarPaymentEntrance;
import com.yxhl.zoume.core.specialcar.model.CarPaymentInfo;
import com.yxhl.zoume.core.tripsmgmt.info.CommentEntrance;
import com.yxhl.zoume.core.tripsmgmt.presenter.detail.DetailTripContainerPresenter;
import com.yxhl.zoume.core.tripsmgmt.presenter.unit.CancelOrderPresenter;
import com.yxhl.zoume.core.tripsmgmt.presenter.unit.CommentOnDriverPresenter;
import com.yxhl.zoume.core.tripsmgmt.ui.activity.TripDetailContainerActivity;
import com.yxhl.zoume.core.tripsmgmt.ui.adapter.PassengerDetailAdapter;
import com.yxhl.zoume.core.tripsmgmt.ui.event.CancelTripOrderEvent;
import com.yxhl.zoume.core.tripsmgmt.ui.event.CancelTripOrderFromDialogEvent;
import com.yxhl.zoume.core.tripsmgmt.view.detail.DetailOrderView;
import com.yxhl.zoume.core.tripsmgmt.view.unit.CancelOrderView;
import com.yxhl.zoume.data.rxbus.RxBus;
import com.yxhl.zoume.di.component.trip.DaggerTripComponent;
import com.yxhl.zoume.di.module.ActivityModule;
import com.yxhl.zoume.di.module.trip.TripModule;
import com.yxhl.zoume.utils.LOG;
import com.yxhl.zoume.utils.PromptUtils;
import com.yxhl.zoume.utils.StringUtils;

import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import rx.functions.Action1;

/**
 * Created by sugarya
 * 快车详情页面
 */
public class SpecialCarTripDetailFragment extends BaseFragment implements DetailOrderView, CancelOrderView {

    private static final String TAG = "SpecialCarTripDetailFrag";

    //widgets
    //头部站点信息
    @BindView(R.id.rl_include_trip_detail_station_info)
    RelativeLayout stationInfoRl;

    @BindView(R.id.iv_include_trip_detail_type_info_icon)
    ImageView ivTypeIcon;
    @BindView(R.id.tv_include_trip_detail_station_info_start)
    TextView stationInfoStartTv;
    @BindView(R.id.tv_include_trip_detail_station_info_clock)
    TextView stationInfoClockTv;
    @BindView(R.id.tv_include_trip_detail_station_info_date)
    TextView stationInfoDateTv;
    @BindView(R.id.tv_include_trip_detail_station_info_destination)
    TextView stationInfoDestinationTv;

    //巴士信息
    @BindView(R.id.ll_special_car_trip_detail_bus_info_bar)
    LinearLayout busInfoBarLl;
    @BindView(R.id.tv_special_car_trip_detail_bus_info)
    TextView busInfoTv;

    //乘客信息栏
    @BindView(R.id.tv_include_trip_detail_passenger_info_count_content)
    TextView passengerInfoCountContentTv;
    @BindView(R.id.iv_include_trip_detail_passenger_info_rotation)
    ImageView passengerInfoArrowIv;

    @BindView(R.id.lvw_special_car_passenger_info_detail)
    ListViewWrap passengerDetailLvw;

    //订单信息栏
    @BindView(R.id.tv_include_trip_detail_order_id_content)
    TextView orderIdContentTv;
    @BindView(R.id.tv_include_trip_detail_order_status_content)
    TextView orderStatusContentTv;
    @BindView(R.id.tv_include_trip_detail_order_create_time_content)
    TextView orderCreateTimeContentTv;

    @BindView(R.id.ll_include_trip_detail_order_payment_fee)
    LinearLayout orderPaymentFeeLl;
    @BindView(R.id.tv_include_trip_detail_order_payment_fee_content)
    TextView orderPaymentFeeContentTv;

    //评价司机栏
    @BindView(R.id.rl_include_trip_detail_judge_info)
    RelativeLayout judgeInfoRl;

    @BindView(R.id.cbl_include_trip_detail_judge)
    CheckBoxLayout judgeCbl;
    @BindView(R.id.tv_include_trip_detail_judge)
    TextView judgeTv;

    //底栏
    @BindView(R.id.frame_special_car_bottom_container)
    FrameLayout bottomContainerFrame;
    //支付
    @BindView(R.id.ll_special_car_bottom_payment)
    LinearLayout bottomPaymentLl;
    @BindView(R.id.tv_special_car_bottom_payment)
    TextView bottomPaymentTv;
    //取消订单
    @BindView(R.id.ll_special_car_bottom_cancel_order)
    LinearLayout bottomCancelOrderLl;
    @BindView(R.id.tv_special_car_bottom_cancel_order)
    TextView bottomCancelOrderTv;

    @BindView(R.id.ll_server_comment)
    LinearLayout mLlServerComment;  //服务评价
    //优惠券
    @BindView(R.id.ll_trip_detail_coupon)
    LinearLayout mLlTripDetailCoupon;  //详情优惠
    @BindView(R.id.tv_trip_detail_coupon_original)
    TextView mTvTripDetailCouponOriginal;  //原价
    @BindView(R.id.tv_trip_detail_coupon_discount)
    TextView mTvTripDetailCouponDiscount;  //差价
    @BindView(R.id.iv_trip_detail_payment_arrow)
    ImageView mIvTripDetailPaymentArrow;  // 展开箭头

//    @BindDrawable(R.drawable.ic_kuaiche)
//    Drawable specialCarIcon;

    //arguments
    @Inject
    DetailTripContainerPresenter mDetailTripContainerPresenter;
    @Inject
    CancelOrderPresenter mCancelOrderPresenter;
    @Inject
    CommentOnDriverPresenter mCommentOnDriverPresenter;


    /**
     * 上一页传递来的数据
     */
    private BizOrder mBizOrder;
    /**
     * 取消订单等待对话框
     */
    private MaterialDialog mDialogForWaitingCancel;
    private PassengerDetailAdapter mPassengerDetailAdapter;
    private boolean needDisplayPassengerList = true;
    private int mFromDegree = 0;
    private int mToDegree = 180;

    public SpecialCarTripDetailFragment() {
        // Required empty public constructor
    }

    public static SpecialCarTripDetailFragment newInstance(BizOrder bizOrder) {
        Bundle args = new Bundle();
        args.putSerializable(UIConstants.TripContainer.ARGUMENT_KEY_SPECIAL_CAR_TRIP_DETAIL, bizOrder);
        SpecialCarTripDetailFragment fragment = new SpecialCarTripDetailFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        handleArguments();
        onRxBusEvent();
    }

    private void handleArguments() {
        Bundle arguments = getArguments();
        if (arguments != null) {
            mBizOrder = (BizOrder) arguments.getSerializable(UIConstants.TripContainer.ARGUMENT_KEY_SPECIAL_CAR_TRIP_DETAIL);
        }
    }

    private void onRxBusEvent() {
        getSubscription().add(toSubscription(CancelTripOrderFromDialogEvent.class,
                new Action1<CancelTripOrderFromDialogEvent>() {
                    @Override
                    public void call(CancelTripOrderFromDialogEvent cancelTripOrderFromDialogEvent) {
                        if (mCancelOrderPresenter != null) {
                            mCancelOrderPresenter.cancelOrder(mBizOrder.getOrderSerial());
                        }
                    }
                },
                new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        LOG.e(TAG, "throwable=" + throwable.toString());
                        onRxBusEvent();
                    }
                }
        ));
        getSubscription().add(toSubscription(
                CommentOnDriverEvent.class,
                new Action1<CommentOnDriverEvent>() {
                    @Override
                    public void call(CommentOnDriverEvent commentOnDriverEvent) {
                        int point = commentOnDriverEvent.getPoint();
                        CommentEntrance commentEntrance = commentOnDriverEvent.getCommentEntrance();

//                        switch (commentEntrance) {
//                            case SPECIAL_CAR_TRIP_DETAIL:
                        judgeInfoRl.setVisibility(View.VISIBLE);
                        showJudgePoint(point);
//                                break;
//                        }
                    }
                },
                new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        LOG.e(TAG, "throwable=" + throwable.toString());
                        onRxBusEvent();
                    }
                }
        ));

        getSubscription().add(toSubscription(
                PayResultEvent.class,
                new Action1<PayResultEvent>() {
                    @Override
                    public void call(PayResultEvent payResultEvent) {
                        switch (payResultEvent.getPayStatus()) {
                            case STATUS_ENUM_TRUE: {
                                judgeInfoRl.setVisibility(View.VISIBLE);
                                break;
                            }
                        }
                    }
                },
                new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        LOG.e(TAG, "throwable=" + throwable.toString());
                        onRxBusEvent();
                    }
                }
        ));
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);
        ViewCompat.setTransitionName(stationInfoRl, UIConstants.TripContainer.TRIP_DETAIL_SHARE_ELEMENT);
        mDetailTripContainerPresenter.attachView(this);
        mCancelOrderPresenter.attachView(this);
        mCommentOnDriverPresenter.attachView(this);
        initializeShow(mBizOrder);
        bindData(mBizOrder);
        ButterKnife.bind(this, view != null ? view : null);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mDetailTripContainerPresenter.getDetailTripOrder(mBizOrder.getOrderSerial());

    }

    @Override
    public void onStart() {
        super.onStart();
        mLlServerComment.setClickable(false);
        setCommentItemEnable();

    }

    private void setCommentItemEnable() {
        if (View.VISIBLE == judgeCbl.getVisibility()) {
            mLlServerComment.setClickable(true);
        }
    }

    @OnClick(R.id.ll_include_trip_detail_passenger_info)
    public void onPassengerArrowClick(View v) {
        startArrowAnimator();
    }

    /**
     * 去支付
     *
     * @param v
     */
    @OnClick(R.id.ll_special_car_bottom_payment)
    public void onBottomPaymentClick(View v) {
        CarPaymentInfo specialCarPaymentInfo = getSpecialCarPaymentInfo(mBizOrder);
        getAppComponent().navigator().navigateToSpecialCarPayment(getActivity(), specialCarPaymentInfo);
    }


    private CarPaymentInfo getSpecialCarPaymentInfo(BizOrder bizOrder) {
        CarPaymentInfo specialCarPaymentInfo = new CarPaymentInfo();

        CarPaymentEntrance currentEntrance = null;
        OrderBizType bizType = bizOrder.getBizType();
        switch (bizType){
            case ORDER_BIZ_CHARTER:
                currentEntrance = CarPaymentEntrance.CAR_PAYMENT_ENTRANCE_SPECIAL_CAR_CHARTER;
                break;
            case ORDER_BIZ_SHARE:
                currentEntrance = CarPaymentEntrance.CAR_PAYMENT_ENTRANCE_SPECIAL_CAR_SHARE;
                break;
        }


        specialCarPaymentInfo.setOrderId(bizOrder.getOrderSerial())
                .setCarPaymentEntrance(currentEntrance)
                .setTotalFee(bizOrder.getTotalFee() + "")
                .setBizType(bizOrder.getBizTypeValue())
                .setDriverName(bizOrder.getDriverName())
                .setPlateNumber(bizOrder.getVehicleNo())
                .setHistoryScore(Double.valueOf((TextUtils.isEmpty(bizOrder.getAvgDriverPoint())) ? "4" : bizOrder.getAvgDriverPoint()));

        return specialCarPaymentInfo;
    }

    /**
     * 取消订单
     *
     * @param view
     */
    @OnClick(R.id.ll_special_car_bottom_cancel_order)
    public void onBottomCancelOrder(View view) {
        ((TripDetailContainerActivity) mActivity).replaceFragment(
                R.id.frame_activity_trip_detail_container,
                CancelCarOrderFeedbackFragment.newInstance(mBizOrder.getOrderSerial()),
                true
        );
    }

    /**
     * 去评价
     */
    @OnClick(R.id.tv_include_trip_detail_judge)
    public void onJudgeClick() {
        //getAppComponent().navigator().navigateToCommentOnDriverActivity(mActivity, mBizOrder, CommentEntrance.SPECIAL_CAR_TRIP_DETAIL);
        // TODO: 16/9/22   可能需要处理评价关闭页面的显示结果
        AppraisalDriverInfo driverInfo = getAppraisalDriverInfo();
        getAppComponent().navigator().navigateToAppraisal(mActivity, driverInfo);
    }

    private AppraisalDriverInfo getAppraisalDriverInfo() {
        AppraisalDriverInfo driverInfo = new AppraisalDriverInfo();
        driverInfo.setOrderId(mBizOrder.getOrderSerial())
                .setDriverName(mBizOrder.getDriverName())
                .setHistoryScore(Double.valueOf(TextUtils.isEmpty(mBizOrder.getAvgDriverPoint())?"4":mBizOrder.getAvgDriverPoint()))
                .setPlateNumber(mBizOrder.getVehicleNo());
        return driverInfo;
    }

    /**
     * 跳转到评价点击
     */
    @OnClick(R.id.ll_server_comment)
    public void onClick() {
        navigateToAppraisalResult(mActivity, getAppraisalDriverInfo());
    }

    /**
     * 跳转到评价结果页面
     *
     * @param activity
     * @param driverInfo
     */
    private void navigateToAppraisalResult(Activity activity, AppraisalDriverInfo driverInfo) {
        Intent intent = AppraisalConfirmActivity.getCallingIntent(activity, driverInfo);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);

    }

    private void startArrowAnimator() {
        ValueAnimator passengerArrowAnimator = ObjectAnimator.ofFloat(passengerInfoArrowIv, "rotation", mFromDegree, mToDegree);
        passengerArrowAnimator.setDuration(UIConstants.TRIP_DETAIL_ARROW_ROTATION_DURATION);
        passengerArrowAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                super.onAnimationStart(animation);
                if (needDisplayPassengerList) {
                    passengerDetailLvw.setVisibility(View.VISIBLE);
                    mFromDegree = 180;
                    mToDegree = 360;
                } else {
                    passengerDetailLvw.setVisibility(View.GONE);
                    mFromDegree = 0;
                    mToDegree = 180;
                }
                needDisplayPassengerList = !needDisplayPassengerList;
            }
        });
        passengerArrowAnimator.start();
    }


    private void initializeShow(BizOrder bizOrder) {
        OrderPayStatus payStatus = bizOrder.getPayStatus();
        OrderRideStatus rideStatus = bizOrder.getRideStatus();

        //改变顶部信息
        //   exchangeStationInfoIcon();
        //车辆信息
        exchangeBusContentInfo();
        //改变乘车人箭头状态
        exchangePassengerArrowStyle(bizOrder);
        //支付金额 接驳车
        exchangeOrderFeeStyle();
        //司机评价栏
        exchangeJudgeDriverStyle(rideStatus);
        //改变底部信息栏信息
        exchangeBottomBarStyle(payStatus, rideStatus);

    }

    private void bindData(BizOrder bizOrder) {
        OrderRideStatus rideStatus = bizOrder.getRideStatus();
        //头部站点信息
        setStartStation(bizOrder.getStart());
        setDestination(bizOrder.getDestination());
        setStartTimeAndData(bizOrder.getGmtDepart());

        //巴士信息
        setBusContent(bizOrder);

        //乘车人数
        setPassengerCount(bizOrder.getAmount());

        //订单状态信息
        setOrderId(bizOrder.getOrderSerial());
        setOrderStatus(bizOrder);
        setGmtCreate(bizOrder.getGmtCreate());
        setTotalFee(bizOrder.getTotalFee());

        //评论
        JudgeEntry judgeEntry = bizOrder.getJudge();
        setDriverJudge(judgeEntry);

        //coupon
        setCouponInfo(bizOrder);
    }

    private void setCouponInfo(BizOrder bizOrder) {
        mTvTripDetailCouponOriginal.setText("¥" + bizOrder.getOrderTotalFee());
        mTvTripDetailCouponDiscount.setText("－¥" + bizOrder.getDiscountFee());

    }


    private void exchangeBusContentInfo() {
        busInfoBarLl.setVisibility(View.VISIBLE);
    }


    private void exchangePassengerArrowStyle(BizOrder bizOrder) {
        /*
      乘客列表信息是否展开
     */
        List<Contract> passengerList = bizOrder.getPassengerList();
        if (passengerList != null && passengerList.size() > 0) {
            if (mPassengerDetailAdapter == null) {
                mPassengerDetailAdapter = new PassengerDetailAdapter(
                        mActivity,
                        passengerList,
                        getChildFragmentManager(),
                        mBizOrder.getOrderSerial()
                );
                passengerDetailLvw.setAdapter(mPassengerDetailAdapter);
            } else {
                mPassengerDetailAdapter.notifyDataSetChanged();
            }
            passengerInfoArrowIv.setVisibility(View.VISIBLE);
        } else {
            passengerInfoArrowIv.setVisibility(View.INVISIBLE);
        }
    }

    private void exchangeJudgeDriverStyle(OrderRideStatus rideStatus) {
        switch (rideStatus) {
            case ARRIVED:
                judgeInfoRl.setVisibility(View.VISIBLE);
                break;
            default:
                judgeInfoRl.setVisibility(View.GONE);
                break;
        }
    }

    private void exchangeOrderFeeStyle() {
        orderPaymentFeeLl.setVisibility(View.GONE);
    }

    private void exchangeBottomBarStyle(OrderPayStatus payStatus, OrderRideStatus rideStatus) {
        switch (rideStatus) {
            case UN_SEND://未派车
                bottomContainerFrame.setVisibility(View.VISIBLE);
                bottomPaymentLl.setVisibility(View.GONE);
                bottomCancelOrderLl.setVisibility(View.VISIBLE);
                break;
            case UN_TAKEN://未上车
                bottomContainerFrame.setVisibility(View.VISIBLE);
                bottomPaymentLl.setVisibility(View.GONE);
                bottomCancelOrderLl.setVisibility(View.VISIBLE);
                break;
            case TAKEN://已上车
            case PART_TAKEN: //部分上车
                break;
            case ARRIVED://已到站
            case PART_ARRIVED: //部分已到站
                break;
            case RIDE_INVALID://未乘坐
            case DROP: //已放弃
                break;
            default:
        }
    }

    /**
     * 显示出发地
     *
     * @param station
     */
    private void setStartStation(String station) {
        if (!TextUtils.isEmpty(station)) {
            stationInfoStartTv.setText(station);
        } else {
            stationInfoStartTv.setText("");
        }
    }

    /**
     * 显示目的地
     *
     * @param station
     */
    private void setDestination(String station) {
        if (!TextUtils.isEmpty(station)) {
            stationInfoDestinationTv.setText(station);
        } else {
            stationInfoDestinationTv.setText("");
        }
    }

    /**
     * 显示出发时刻和日期
     *
     * @param timeStamp
     */
    private void setStartTimeAndData(String timeStamp) {
        if (!TextUtils.isEmpty(timeStamp)) {
            String[] strings = timeStamp.split(" ");
            if (strings != null) {
                stationInfoDateTv.setText(strings[0]);
                stationInfoClockTv.setText(strings[1]);
            }
        }
    }

    /**
     * 巴士信息
     *
     * @param bizOrder
     */
    private void setBusContent(BizOrder bizOrder) {
        String vehicleNo = bizOrder.getVehicleNo();
        String driverCalledName = StringUtils.getCalledName(bizOrder.getDriverName());
        if (!TextUtils.isEmpty(vehicleNo)) {
            busInfoTv.setText(driverCalledName + "   " + vehicleNo);
        } else {
            busInfoTv.setText("车辆调派中");
        }
    }


    /**
     * 显示乘客人数
     *
     * @param amount
     */
    private void setPassengerCount(int amount) {
        passengerInfoCountContentTv.setText(amount + "人");
    }

    /**
     * 显示订单编号
     *
     * @param orderId
     */
    private void setOrderId(String orderId) {
        if (!TextUtils.isEmpty(orderId)) {
            orderIdContentTv.setText(orderId);
        }
    }

    /**
     * 显示行程状态
     */
    private void setOrderStatus(BizOrder bizOrder) {
        OrderRideStatus rideStatus = bizOrder.getRideStatus();
        OrderPayStatus payStatus = bizOrder.getPayStatus();
        String rideStatusStr = getTripStatusForSpecialCar(rideStatus, payStatus, bizOrder);
        orderStatusContentTv.setText(rideStatusStr);
    }

    private String getTripStatusForSpecialCar(OrderRideStatus rideStatus, OrderPayStatus payStatus, BizOrder bizOrder) {
        String tripStatusStr;
        switch (rideStatus) {
            case UN_SEND://未派车
                tripStatusStr = getString(R.string.route_detail_no_charter);
                break;
            case UN_TAKEN://未上车
                tripStatusStr = getString(R.string.route_detail_wait_charter);
                break;
            case TAKEN://已上车
            case PART_TAKEN: {//部分上车
                if (payStatus == OrderPayStatus.OPS_SEND_BILL) {
                    tripStatusStr = "等待支付";
                    showTotalFee(bizOrder.getTotalFee());
                    showPayment(bizOrder);
                } else {
                    tripStatusStr = "已上车";
                }
                break;
            }
            case ARRIVED://已到站
            case PART_ARRIVED: //部分已到站
                if (payStatus == OrderPayStatus.PAID) {
                    tripStatusStr = "已支付";
                } else {
                    tripStatusStr = getString(R.string.route_detail_finish_charter);
                }

                judgeInfoRl.setVisibility(View.VISIBLE);
                showTotalFee(bizOrder.getTotalFee());
                setDriverJudge(bizOrder.getJudge());
                break;
            case RIDE_INVALID://未乘坐
            case DROP: //已放弃
                tripStatusStr = getString(R.string.route_detail_cancel_charter);
                break;
            default:
                tripStatusStr = "";
        }
        return tripStatusStr;
    }

    /**
     * 去支付
     *
     * @param bizOrder
     */
    private void showPayment(BizOrder bizOrder) {
        bottomPaymentLl.setVisibility(View.VISIBLE);
        mBizOrder = bizOrder;
    }

    /**
     * 显示下单时间
     *
     * @param time
     */
    private void setGmtCreate(String time) {
        if (!TextUtils.isEmpty(time)) {
            orderCreateTimeContentTv.setText(time);
        }
    }

    /**
     * 显示总费用
     *
     * @param fee
     */
    private void setTotalFee(double fee) {
        if (fee >= 0) {
            orderPaymentFeeContentTv.setText(fee + "元");
        } else {
            orderPaymentFeeContentTv.setText("");
        }
    }

    /**
     * 显示总费用
     *
     * @param fee
     */
    private void showTotalFee(double fee) {
        orderPaymentFeeLl.setVisibility(View.VISIBLE);
        if (fee >= 0) {
            orderPaymentFeeContentTv.setText(fee + "元");
        } else {
            orderPaymentFeeContentTv.setText("");
        }
    }

    /**
     * 评价司机
     *
     * @param judgeEntry
     */
    private void setDriverJudge(JudgeEntry judgeEntry) {

        if (judgeEntry != null) {
            int judgePoint = judgeEntry.getJudgePoint();
            if (judgePoint > 0) {
                showJudgePoint(judgePoint);
            } else {
                judgeCbl.setVisibility(View.INVISIBLE);
                judgeTv.setVisibility(View.VISIBLE);
            }
        }
    }

    /**
     * 显示评价信息数
     *
     * @param judgePoint
     */
    private void showJudgePoint(int judgePoint) {
        judgeInfoRl.setVisibility(View.VISIBLE);
        judgeCbl.setCheckedCount(judgePoint);
        judgeCbl.setVisibility(View.VISIBLE);
        judgeCbl.setClickable(false);
        judgeTv.setVisibility(View.INVISIBLE);
    }

    @Override
    public void renderDetailOrderOnSuccess(BizOrderResponse bizOrderResponse) {
        List<BizOrder> bizOrderList = bizOrderResponse.getOrderFieldsesList();
        if (bizOrderList != null && bizOrderList.size() > 0) {
            mBizOrder = bizOrderList.get(0);
            if (mBizOrder != null) {
                initializeShow(mBizOrder);
                bindData(mBizOrder);
            }
        }
    }

    @Override
    public void renderDetailOrderOnFailure() {
    }

    @Override
    public void renderCancelOrderResult(boolean isCanceled) {
        if (isCanceled) {
            PromptUtils.showShort(mActivity, getString(R.string.cancel_order_success));
            RxBus.getInstance().send(new CancelTripOrderEvent(mBizOrder.getOrderSerial()));
            mActivity.finish();
        } else {
            PromptUtils.showLong(getActivity(), getString(R.string.trip_cancel_order_failure));
        }
    }

    @Override
    public void renderCancelError() {
        PromptUtils.showShort(mActivity, getString(R.string.trip_cancel_order_error));
    }

    @Override
    public void waitingForOrderCancel(boolean isWaiting) {
        if (isWaiting) {
            mDialogForWaitingCancel = new MaterialDialog.Builder(getActivity())
                    .content(R.string.dialog_waiting_canceling)
                    .progress(true, 0)
                    .canceledOnTouchOutside(false)
                    .show();
        } else {
            if (null != mDialogForWaitingCancel) {
                mDialogForWaitingCancel.dismiss();
            }
        }
    }


    @Override
    protected void initializeInjector() {
        DaggerTripComponent
                .builder()
                .appComponent(getAppComponent())
                .activityModule(new ActivityModule(mActivity))
                .tripModule(new TripModule())
                .build()
                .inject(this);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.fragment_special_car_trip_detail;
    }

    @Override
    protected void setupToolBar() {
        ((TripDetailContainerActivity) mActivity).setToolbar(getString(R.string.trip_detail_header_title), R.drawable.icon_share);
    }

    @OnClick(R.id.ll_include_trip_detail_order_payment_fee)
    public void onDetailCuoponClick() {
        int visibility = mLlTripDetailCoupon.getVisibility();
        if (visibility == View.GONE) {
            mLlTripDetailCoupon.setVisibility(View.VISIBLE);
            triangleAnimationStart();
        } else {
            mLlTripDetailCoupon.setVisibility(View.GONE);
            triangleAnimationEnd();
        }

    }

    private void triangleAnimationStart() {
        RotateAnimation rotateAnimation = new RotateAnimation(0, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        rotateAnimation.setDuration(200);
        rotateAnimation.setFillAfter(true);
        mIvTripDetailPaymentArrow.startAnimation(rotateAnimation);
    }

    private void triangleAnimationEnd() {
        RotateAnimation rotateAnimation = new RotateAnimation(180, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        rotateAnimation.setDuration(200);
        rotateAnimation.setFillAfter(true);
        mIvTripDetailPaymentArrow.startAnimation(rotateAnimation);
    }


}
